<?php
/**
 * Created by PhpStorm.
 * Author: MeiJay
 * Date: 2018/11/3
 * Time: 15:36
 */

namespace App\Http\Controllers\Web\V1;


use App\Exceptions\WebExceptions\AuthException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redis;

class AuthController extends BaseController
{

    public function login()
    {
        return view('web.auth.login');
    }


    public function auth(Request $request)
    {
        $input = $request->only('phone','password');
        $messages = [
            'phone.required' => '请填写手机号码!',
            'password.required' => '请填写密码!',
        ];
        $validator = Validator::make($input, [
            'phone' => 'required',
            'password' => 'required',
        ],$messages);

        if ($validator->fails()) {

            throw new AuthException($validator->errors());
        }
        if ($input['phone'] == '18888888888' && $input['password'] == 'shaishai') {

            Redis::setex('isLogin',3600,1);
            success();
        }
        throw new AuthException('密码或者用户名不正确');

    }

}